﻿#include "stdafx.h"
#include "W_FieldMonitor.h"

#include "Source/ModelingPreModule/S_ModelingPre_InteractiveManager.h"
#include "Source/ResultModule/S_ResultWindowManager.h"
#include "Source/SourceModule/S_SourceDataContainer.h"
#include "Source/MainModule/Global/S_TabOrderManager.h"
#include "Source/SettingModule/S_SettingDataContainer.h"
#include "Source/SettingModule/BoundariesCalculator/S_SettingBoundariesCalculator_ForDisplay.h"

#include "Source/Utils/WidgetForm/QStringListEditor/W_QStringListEditor.h"
#include "Source/Utils/Common/TTool.h"

/*
-----==========================================================-----
		类：			场监视器 窗口类.h
		作者：			杨骁
		所属模块：		场监视器模块
		功能：			场监视器模块的窗口类对象
-----==========================================================-----
*/
W_FieldMonitor::W_FieldMonitor(QWidget *parent) :
	W_DialogBase(parent),
	ui(new Ui::W_FieldMonitor)
{
	ui->setupUi(this);

	//-----------------------------------
	//----参数初始化
	this->m_slotBlock_model = false;

	//-----------------------------------
	//----ui初始化
	this->m_MonitorTypeGroup = new QButtonGroup(this);
	this->m_SpecificationTypeGroup = new QButtonGroup(this);

	this->m_MonitorTypeGroup->addButton(ui->radioButton_eField, 0);
	this->m_MonitorTypeGroup->addButton(ui->radioButton_hField, 1);
	this->m_MonitorTypeGroup->addButton(ui->radioButton_rcs, 2);
	this->m_MonitorTypeGroup->addButton(ui->radioButton_fieldSource, 3);
	this->m_MonitorTypeGroup->addButton(ui->radioButton_monoRCS, 4);

	this->m_SpecificationTypeGroup->addButton(ui->radioButton_frequency, 0);
	this->m_SpecificationTypeGroup->addButton(ui->radioButton_time, 1);

	ui->checkBox_auto->setCheckState(this->m_FieldMonitor.getAutoNameState() ? Qt::Checked : Qt::Unchecked);
	ui->comboBox_freq->addItems(this->m_FieldMonitor.getFieldItems());
	ui->widget_farfieldSource->setVisible(this->m_MonitorTypeGroup->checkedId() == 2);

	// > RCS勾选（与平面波是否设置相关）
	C_PlaneWave planeWaveData = S_SourceDataContainer::getInstance()->getDataPlaneWave();
	ui->radioButton_monoRCS->setEnabled(!planeWaveData.isNull());


	//-----------------------------------
	//----事件绑定
	connect(m_MonitorTypeGroup, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &W_FieldMonitor::onMonitorType);
	this->m_MonitorTypeGroup->button(m_FieldMonitor.getMonitorType())->setChecked(true);

	connect(m_SpecificationTypeGroup, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &W_FieldMonitor::onSpecificationType);
    
	// > 名称
	connect(ui->checkBox_auto, &QCheckBox::stateChanged, this, &W_FieldMonitor::refreshUiName);
	
	// > 时域
	connect(ui->lineEdit_startTime, &QLineEdit::textChanged, this, &W_FieldMonitor::refreshUiName);
	connect(ui->lineEdit_endTime, &QLineEdit::textChanged, this, &W_FieldMonitor::refreshUiName);
	connect(ui->checkBox_useEndTime, &QCheckBox::toggled, this, &W_FieldMonitor::refreshUiName);

	// > 频域
	connect(ui->comboBox_freq, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index) {
		m_FieldMonitor.setFreqType(index);
		});
	connect(ui->lineEdit_freq, &QLineEdit::textChanged, this, &W_FieldMonitor::refreshUiName);
	connect(ui->toolButton_addMore, &QToolButton::clicked, this, &W_FieldMonitor::btn_addMoreFreq);

	connect(this->m_MonitorTypeGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled), this, &W_FieldMonitor::refreshModel);
	connect(ui->lineEdit_x1, &QLineEdit::textEdited, this, &W_FieldMonitor::refreshModel);
	connect(ui->lineEdit_y1, &QLineEdit::textEdited, this, &W_FieldMonitor::refreshModel);
	connect(ui->lineEdit_z1, &QLineEdit::textEdited, this, &W_FieldMonitor::refreshModel);
	connect(ui->lineEdit_x2, &QLineEdit::textEdited, this, &W_FieldMonitor::refreshModel);
	connect(ui->lineEdit_y2, &QLineEdit::textEdited, this, &W_FieldMonitor::refreshModel);
	connect(ui->lineEdit_z2, &QLineEdit::textEdited, this, &W_FieldMonitor::refreshModel);
	connect(ui->lineEdit_x3, &QLineEdit::textEdited, this, &W_FieldMonitor::refreshModel);
	connect(ui->lineEdit_y3, &QLineEdit::textEdited, this, &W_FieldMonitor::refreshModel);
	connect(ui->lineEdit_z3, &QLineEdit::textEdited, this, &W_FieldMonitor::refreshModel);

	// > 刷新
	this->setDataInAddMode();
	this->initDialogButtonBox(ui->buttonBox);

	
	//-----------------------------------
	//----配置tab顺序
	S_TabOrderManager::getInstance()->configureTabOrder(this);
	

	//-----------------------------------
	//----定制项目的功能隐藏
	#ifdef DSEMUI_Publish_HideFunction_20241206
		ui->radioButton_eField->hide();	//（2025-9-15 谢鹏飞 隐藏电场功能，此功能有但一直报错算不了，几年内看是改不了了）
		ui->radioButton_sc->hide();
		ui->radioButton_pf->hide();
		ui->radioButton_cd->hide();
		ui->radioButton_pld->hide();
		ui->radioButton_eed->hide();
		ui->radioButton_med->hide();
	#endif
	#if defined(DSEMUI_Customized_LargeProject_20241205)
		//（商飞项目不允许出现 RCS）
		ui->radioButton_rcs->hide();
		ui->radioButton_fieldSource->hide();
		ui->radioButton_monoRCS->hide();
	#endif

}
W_FieldMonitor::~W_FieldMonitor(){
	delete ui;
}
Ui::W_FieldMonitor *W_FieldMonitor::getUI(){
	return ui;
}

/*-------------------------------------------------
		控件 - 刷新单位
*/
void W_FieldMonitor::refreshUnit() {

	// > 【频率单位】-临时只读
	C_SettingUnits unit = S_SettingDataContainer::getInstance()->getDataUnits();
	ui->label_freqUnit->setText(unit.getCurrentString_frequency());
	ui->label_freqUnit_2->setText(unit.getCurrentString_frequency());
	ui->label_freqUnit_3->setText(unit.getCurrentString_frequency());
	ui->label_timeUnit_1->setText(unit.getCurrentString_time());
	ui->label_timeUnit_2->setText(unit.getCurrentString_time());
	ui->label_timeUnit_3->setText(unit.getCurrentString_time());
}
/*-------------------------------------------------
		控件 - 添加更多频率
*/
void W_FieldMonitor::btn_addMoreFreq() {
	QString text = ui->lineEdit_freq->text();
	QStringList text_list = text.split(";");
	C_SettingUnits unit = S_SettingDataContainer::getInstance()->getDataUnits();

	W_QStringListEditor d(this);
	d.setParamShowingName(tr("Frequency"));
	d.setParamShowingSuffix(unit.getCurrentString_frequency());
	d.setConditionNotNull(true);
	d.setConditionNoRepeat(true);
	d.setDataInModifyMode(text_list);
	if (d.exec() == QDialog::Accepted) {
		ui->lineEdit_freq->setText(d.getData().join(";"));
	}
}


/*-------------------------------------------------
		模型 - 刷新模型
*/
void W_FieldMonitor::refreshModel() {
	if (this->m_slotBlock_model == true) { return; }

	// > 若已存在，则删除模型
	this->clearModel();

	// > 类型（E-field）模型
	if (ui->radioButton_eField->isChecked() == true) {
		double x1 = ui->lineEdit_x1->text().toDouble();
		double y1 = ui->lineEdit_y1->text().toDouble();
		double z1 = ui->lineEdit_z1->text().toDouble();
		double x2 = ui->lineEdit_x2->text().toDouble();
		double y2 = ui->lineEdit_y2->text().toDouble();
		double z2 = ui->lineEdit_z2->text().toDouble();
		double x3 = ui->lineEdit_x3->text().toDouble();
		double y3 = ui->lineEdit_y3->text().toDouble();
		double z3 = ui->lineEdit_z3->text().toDouble();
		gp_Pnt p1 = gp_Pnt(x1, y1, z1);
		gp_Pnt p2 = gp_Pnt(x2, y2, z2);
		gp_Pnt p3 = gp_Pnt(x3, y3, z3);

		// > 错误的线（出现三点共线时）
		if (C_FieldMonitor::util_isCollinear({ x1, y1, z1 }, { x2, y2, z2 }, { x3, y3, z3 }) == true) {
			QList<gp_Pnt> p_list;
			p_list.append(p1);
			p_list.append(p2);
			p_list.append(p3);
			this->m_modelId = S_ModelingPre_InteractiveManager::getInstance()->model_CreateMultiLine(p_list, QColor(205, 55, 0), 4);	//橙色线
			return;
		}

		// > 正确的线
		DSEM::Point3D p4 = C_FieldMonitor::util_getQuadrilateralVertex({ x1, y1, z1 }, { x2, y2, z2 }, { x3, y3, z3 });
		QList<gp_Pnt> p_list;
		p_list.append(p1);
		p_list.append(p2);
		p_list.append(p3);
		p_list.append({ p4.X(), p4.Y(), p4.Z() });
		p_list.append(p1);
		this->m_modelId = S_ModelingPre_InteractiveManager::getInstance()->model_CreateMultiLine(p_list, QColor(0, 198, 0), 4);		//绿色线
	}

	// > 类型（H-field 表面电流）模型
	if (ui->radioButton_hField->isChecked() == true) {
		double min_x = 0; double min_y = 0; double min_z = 0;
		double max_x = 0; double max_y = 0; double max_z = 0;
		S_SettingBoundariesCalculator_ForDisplay::getInstance()->getBoundaries_ForDisplay(min_x, min_y, min_z, max_x, max_y, max_z);
		if (min_x == max_x) { return; }
		if (min_y == max_y) { return; }
		if (min_z == max_z) { return; }

		// > 绘制绑定范围
		QList<QPair<gp_Pnt, gp_Pnt>> point_list;
		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(min_x, min_y, min_z), gp_Pnt(max_x, min_y, min_z)));
		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(min_x, min_y, min_z), gp_Pnt(min_x, max_y, min_z)));
		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(min_x, min_y, min_z), gp_Pnt(min_x, min_y, max_z)));

		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(max_x, max_y, max_z), gp_Pnt(min_x, max_y, max_z)));
		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(max_x, max_y, max_z), gp_Pnt(max_x, min_y, max_z)));
		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(max_x, max_y, max_z), gp_Pnt(max_x, max_y, min_z)));

		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(min_x, min_y, max_z), gp_Pnt(max_x, min_y, max_z)));
		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(min_x, min_y, max_z), gp_Pnt(min_x, max_y, max_z)));
		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(min_x, max_y, min_z), gp_Pnt(min_x, max_y, max_z)));

		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(min_x, max_y, min_z), gp_Pnt(max_x, max_y, min_z)));
		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(max_x, min_y, min_z), gp_Pnt(max_x, max_y, min_z)));
		point_list.append(QPair<gp_Pnt, gp_Pnt>(gp_Pnt(max_x, min_y, min_z), gp_Pnt(max_x, min_y, max_z)));

		QString model_id = S_ModelingPre_InteractiveManager::getInstance()->model_CreateMultiLine(point_list, QColor(0,0,255), 8);
		this->m_modelId = model_id;
	}

}
/*-------------------------------------------------
		模型 - 删除模型
*/
void W_FieldMonitor::clearModel() {
	if (this->m_modelId != "") {
		S_ModelingPre_InteractiveManager::getInstance()->model_destory(this->m_modelId);
	}
}



/*-------------------------------------------------
		窗口 - 设置三点的数据
*/
void W_FieldMonitor::setDataPoint(QList<double> p1, QList<double> p2, QList<double> p3) {
	if (p1.count() < 3) { return; }
	ui->lineEdit_x1->setText(QString::number(p1.at(0)));
	ui->lineEdit_y1->setText(QString::number(p1.at(1)));
	ui->lineEdit_z1->setText(QString::number(p1.at(2)));

	if (p2.count() < 3) { return; }
	ui->lineEdit_x2->setText(QString::number(p2.at(0)));
	ui->lineEdit_y2->setText(QString::number(p2.at(1)));
	ui->lineEdit_z2->setText(QString::number(p2.at(2)));

	if (p3.count() < 3) { return; }
	ui->lineEdit_x3->setText(QString::number(p3.at(0)));
	ui->lineEdit_y3->setText(QString::number(p3.at(1)));
	ui->lineEdit_z3->setText(QString::number(p3.at(2)));

	// > 刷新模型
	this->refreshModel();
}
/*-------------------------------------------------
		窗口 - 设置数据（添加）
*/
void W_FieldMonitor::setDataInAddMode() {
	this->m_FieldMonitor.init();
	this->isAddMode = true;
	this->putDataToUi(); 
}
/*-------------------------------------------------
		窗口 - 设置数据（修改）
*/
void W_FieldMonitor::setDataInModifyMode(C_FieldMonitor p) {
	this->m_FieldMonitor = p;
	this->isAddMode = false;
	this->putDataToUi(); 
}
/*-------------------------------------------------
		窗口 - 取出数据
*/
C_FieldMonitor W_FieldMonitor::getData() {
	return this->m_FieldMonitor;
};
/*-------------------------------------------------
		窗口 - 本地数据 -> ui数据
*/
void W_FieldMonitor::putDataToUi() {
	this->m_slotBlock_model = true;

	m_MonitorTypeGroup->button(m_FieldMonitor.getMonitorType())->setChecked(true);
	
	// farfield不需要传入网格坐标
	ui->widget_points->setVisible(m_FieldMonitor.getMonitorType() == 0);

	// > 名称
	ui->lineEdit_name->setText(m_FieldMonitor.getName());
	ui->checkBox_auto->setCheckState(m_FieldMonitor.getAutoNameState() ? Qt::Checked : Qt::Unchecked);

	// > 【频率值】-给参数赋值（不转单位）
	ui->comboBox_freq->setCurrentIndex(m_FieldMonitor.getFreqType());
	ui->lineEdit_freq_min->setText(QString::number(S_SettingDataContainer::getInstance()->getDataFrequency().getFreqMin()));
	ui->lineEdit_freq_max->setText(QString::number(S_SettingDataContainer::getInstance()->getDataFrequency().getFreqMax()));

	if (this->isAddMode == false) {
		// 不可以下拉
		ui->comboBox_freq->setEnabled(false);
	}

	ui->widget_farfieldSource->setVisible(m_MonitorTypeGroup->checkedId() == 2);

    // > 类型（频域/时域）
	this->m_SpecificationTypeGroup->button(m_FieldMonitor.getSpecType())->setChecked(true);
	ui->stackedWidget_specification->setCurrentIndex(m_FieldMonitor.getSpecType());

	// > 切面片
	ui->lineEdit_x1->setText(QString::number(m_FieldMonitor.x1));
	ui->lineEdit_x2->setText(QString::number(m_FieldMonitor.x2));
	ui->lineEdit_x3->setText(QString::number(m_FieldMonitor.x3));
	ui->lineEdit_y1->setText(QString::number(m_FieldMonitor.y1));
	ui->lineEdit_y2->setText(QString::number(m_FieldMonitor.y2));
	ui->lineEdit_y3->setText(QString::number(m_FieldMonitor.y3));
	ui->lineEdit_z1->setText(QString::number(m_FieldMonitor.z1));
	ui->lineEdit_z2->setText(QString::number(m_FieldMonitor.z2));
	ui->lineEdit_z3->setText(QString::number(m_FieldMonitor.z3));

	// > RCS
	ui->lineEdit_theta->setText(QString::number(m_FieldMonitor.getTheta()));
	ui->lineEdit_phi->setText(QString::number(m_FieldMonitor.getPhi()));
	ui->stackedWidget_RCS->setCurrentIndex(m_FieldMonitor.getMonitorType() == 4 ? 1 : 0);

	// > 频域
	ui->lineEdit_freq->blockSignals(true);
	ui->lineEdit_freq->setText(QString::number(m_FieldMonitor.getFreq()));
	ui->lineEdit_freq->blockSignals(false);

	// > 时域
	ui->lineEdit_startTime->blockSignals(true);
	ui->lineEdit_startTime->setText(QString::number(m_FieldMonitor.getTimeStart()));
	ui->lineEdit_startTime->blockSignals(false);

	ui->lineEdit_stepWidth->setText(QString::number(m_FieldMonitor.getTimeStep()));

	ui->lineEdit_endTime->blockSignals(true);
	ui->lineEdit_endTime->setText(QString::number(m_FieldMonitor.getTimeEnd()));
	ui->lineEdit_endTime->blockSignals(false);

	ui->checkBox_useEndTime->setChecked(m_FieldMonitor.isUseEndTime());

	this->m_slotBlock_model = false;

	// > 刷新
	this->refreshModel();
	this->refreshUnit();
	this->refreshUiName();
};

/*-------------------------------------------------
		窗口 - ui数据 -> 本地数据
*/
void W_FieldMonitor::putUiToData() {
	m_FieldMonitor.setMonitorType(m_MonitorTypeGroup->checkedId());

	// > 名称
	m_FieldMonitor.setName(ui->lineEdit_name->text());
	m_FieldMonitor.setAutoNameState(ui->checkBox_auto->isChecked());

	// > RCS
	m_FieldMonitor.setTheta(TTool::_to_double_(ui->lineEdit_theta->text()));
	m_FieldMonitor.setPhi(TTool::_to_double_(ui->lineEdit_phi->text()));

    // > 类型（频域/时域）
	m_FieldMonitor.setSpecType(m_SpecificationTypeGroup->checkedId());

	// > 切面片
	m_FieldMonitor.x1 = TTool::_to_double_(ui->lineEdit_x1->text());
	m_FieldMonitor.x2 = TTool::_to_double_(ui->lineEdit_x2->text());
	m_FieldMonitor.x3 = TTool::_to_double_(ui->lineEdit_x3->text());
	m_FieldMonitor.y1 = TTool::_to_double_(ui->lineEdit_y1->text());
	m_FieldMonitor.y2 = TTool::_to_double_(ui->lineEdit_y2->text());
	m_FieldMonitor.y3 = TTool::_to_double_(ui->lineEdit_y3->text());
	m_FieldMonitor.z1 = TTool::_to_double_(ui->lineEdit_z1->text());
	m_FieldMonitor.z2 = TTool::_to_double_(ui->lineEdit_z2->text());
	m_FieldMonitor.z3 = TTool::_to_double_(ui->lineEdit_z3->text());

	// > 频域
	QStringList freqList = ui->lineEdit_freq->text().split(";");
	if (freqList.count() > 0) {
		m_FieldMonitor.setFreqs(freqList);
		m_FieldMonitor.setFreq(TTool::_to_double_e_(freqList[0]));
	}else{
		m_FieldMonitor.setFreqs(QStringList());
		m_FieldMonitor.setFreq(0);
	}
	m_FieldMonitor.setFreqType(ui->comboBox_freq->currentIndex());

	// > 时域
	m_FieldMonitor.setTimeStart(TTool::_to_double_(ui->lineEdit_startTime->text()));
	m_FieldMonitor.setTimeStep(TTool::_to_double_(ui->lineEdit_stepWidth->text()));
	m_FieldMonitor.setTimeEnd(TTool::_to_double_(ui->lineEdit_endTime->text()));
	m_FieldMonitor.setUseEndTime(ui->checkBox_useEndTime->isChecked());
};

/*-------------------------------------------------
		窗口 - 提交数据（校验）
*/
void W_FieldMonitor::base_acceptData() {
	this->putUiToData();

	// > 校验 - E-field电场情况
	if (this->m_FieldMonitor.getMonitorType() == 0 && this->m_FieldMonitor.getSpecType() == 0){
		if (this->m_FieldMonitor.isCollinear()) {
			QMessageBox::warning(this, tr("提示"), tr("切面片的三点不能共线。"));
			return;
		}
	}

	// > 校验 - mono RCS情况
	if (this->m_FieldMonitor.getMonitorType() == 4){
		double theta = m_FieldMonitor.getTheta();
		double phi = m_FieldMonitor.getPhi();

		if (theta < 0 || theta > 180){
			QMessageBox::warning(this, tr("提示"), tr("Theta值在[0, 180]，请检查平面波设置。"));
			return;
		}
		if (phi < 0 || phi > 360){
			QMessageBox::warning(this, tr("提示"), tr("Phi值在[0, 360]，请检查平面波设置。"));
			return;
		}
	}

	// > 校验 - 操作是否与结果文件冲突（含迁移处理）
	if (S_ResultWindowManager::getInstance()->isConflictToResult_WithMigrateTip()) {
		return;
	}

	emit acceptDataSignal(this->isAddMode, this->m_FieldMonitor);
	W_DialogBase::base_acceptData();

	// > 清理模型
	this->clearModel();
};

/*-------------------------------------------------
		窗口 - 取消数据（校验）
*/
void W_FieldMonitor::base_rejectData() {
	W_DialogBase::base_rejectData();

	// > 清理模型
	this->clearModel();
}

/*-------------------------------------------------
		窗口 - 关闭事件
*/
void W_FieldMonitor::closeEvent(QCloseEvent *e) {
	W_DialogBase::closeEvent(e);

	// > 清理模型
	this->clearModel();
}

/*-------------------------------------------------
		窗口 - 焦点切换
*/
void W_FieldMonitor::onFocusChanged(QWidget *old, QWidget *now)
{
	if (now != nullptr)
	{
		qDebug() << "here name" << now->objectName();
	}
}

/*-------------------------------------------------
		控件 - 切换显示器类型			
*/
void W_FieldMonitor::onMonitorType(int index) {
	m_FieldMonitor.setMonitorType(index);

	if (index == 4){
		// RCS
		ui->stackedWidget_RCS->setCurrentIndex(1);

		C_PlaneWave planeWaveData = S_SourceDataContainer::getInstance()->getDataPlaneWave();
		if (!planeWaveData.isNull())
		{
			// 计算theta和phi填入
			double px = -planeWaveData.propagation_x;
			double py = -planeWaveData.propagation_y;
			double pz = -planeWaveData.propagation_z;

			double phi, theta;

			double pr = sqrt(px * px + py * py + pz * pz);
			theta = acos(pz / pr) * 180 / M_PI;
			
			if (px && py)
				phi = atan(py / px) * 180 / M_PI;
			else if (px && !py)
			{
				if (px > 0)
					phi = 0;
				else
					phi = 180;
			}
			else if (!px && py)
			{
				if (py > 0)
					phi = 90;
				else
					phi = 270;
			}
			else
				phi = 0;

			ui->lineEdit_theta->setText(QString::number(theta));
			ui->lineEdit_phi->setText(QString::number(phi));
		}
	}
	else if (index == 1){
		// 表面电流


	}else{
		ui->stackedWidget_RCS->setCurrentIndex(0);
	}

	// farfield不需要传入网格坐标
	ui->widget_points->setVisible(index == 0);

	// farfield额外勾选项
	ui->widget_farfieldSource->setVisible(m_MonitorTypeGroup->checkedId() == 2);

	if (m_FieldMonitor.getAutoNameState()) {
		QString name;
		if (m_SpecificationTypeGroup->checkedId() == 1){
			// 时域
			name = this->getMonitorName_Time();
		}else{
			// 频域
			name = this->getMonitorName_Freq();
		}
		m_FieldMonitor.setName(name);
		ui->lineEdit_name->setText(name);
	}
}

/*-------------------------------------------------
		控件 - 切换规格类型			
*/
void W_FieldMonitor::onSpecificationType(int index) {
	if (index == 0 && m_FieldMonitor.getMonitorType() == 0) {
		ui->widget_points->setVisible(true);
	} else {
		ui->widget_points->setVisible(false);
	}

	ui->stackedWidget_specification->setCurrentIndex(index);

    // 刷新名字
	this->refreshUiName();
}

/*-------------------------------------------------
		控件 - 刷新名称
*/
void W_FieldMonitor::refreshUiName() {
	QString name;
	if (m_SpecificationTypeGroup->checkedId() == 1) {
		// 时域
		name = this->getMonitorName_Time();
	} else {
		// 频域
		name = this->getMonitorName_Freq();
	}

	if (ui->checkBox_auto->isChecked()) {
		ui->lineEdit_name->setText(name);
	}
}
/*-------------------------------------------------
		控件 - 获取频域名称
*/
QString W_FieldMonitor::getMonitorName_Freq() {
	QString result;
	result.append(m_FieldMonitor.getMonitorTypeString());
	result.append("  ");
	result.append("(f=");
	QStringList freqList = ui->lineEdit_freq->text().split(";");
	if (freqList.count() > 0) {
		result.append(freqList.first());
	}
	result.append(")");
	return result;
}
/*-------------------------------------------------
		控件 - 获取时域名称
*/
QString W_FieldMonitor::getMonitorName_Time() {
	QString result;
	result.append(m_FieldMonitor.getMonitorTypeString());
	result.append("  ");
	result.append("(t=");
	result.append(ui->lineEdit_startTime->text());
	result.append(" to ");
	if (ui->checkBox_useEndTime->isChecked()) {
		result.append(ui->lineEdit_endTime->text());
	} else {
		result.append("End");
	}
	result.append(")");
	return result;
}